//
//  DSSHTaskNewsAndPublicVC.m
//  DSSH
//
//  Created by lcy on 16/4/12.
//  Copyright © 2016年 lcy. All rights reserved.
//

#import "DSSHTaskNewsAndPublicVC.h"
#import "NewsAndPublicCell.h"
#import "DSSHTaskNewsDetailVC.h"
@interface DSSHTaskNewsAndPublicVC ()<UIScrollViewDelegate,UITableViewDataSource,UITableViewDelegate>
{
    UIView* _redView;
}
@property(nonatomic,strong)UIScrollView*bigScrollerView;
@end

@implementation DSSHTaskNewsAndPublicVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"新闻公告";
    [self setupViewAndData];
    // Do any additional setup after loading the view.
}
-(void)setupViewAndData{
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.view.backgroundColor = [UIColor whiteColor];
    UIBarButtonItem * backBarBtn = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"fanhui"] style:UIBarButtonItemStylePlain target:self action:@selector(backBarBtnClick)];
    self.navigationItem.leftBarButtonItem = backBarBtn;
    //添加上面新闻公告的选择按钮
    UIButton * newsButton = [UIButton new];
    newsButton.frame = CGRectMake(0, 64, ZYAppWidth/2, 40*HIGHT_SCALE);
    [newsButton setTitle:@"新闻" forState:UIControlStateNormal];
    [newsButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    newsButton.titleLabel.font = FONT(13);
    [newsButton addTarget:self action:@selector(clickNewsBtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:newsButton];
    
    UIButton * publicButton = [UIButton new];
    publicButton.titleLabel.font = FONT(13);
    publicButton.backgroundColor = [UIColor whiteColor];
    publicButton.frame = CGRectMake(ZYAppWidth/2, 64, ZYAppWidth/2, 40*HIGHT_SCALE);
    [publicButton setTitle:@"公告" forState:UIControlStateNormal];
    [publicButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [publicButton addTarget:self action:@selector(clickPublicBtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:publicButton];
    //添加下面红线
    _redView = [[UIView alloc]init];
    _redView.center = CGPointMake(newsButton.center.x, newsButton.center.y+16*HIGHT_SCALE);
    _redView.bounds = CGRectMake(0, 0, 100*WIDTH_SCALE, 4);
    _redView.backgroundColor = COLOR_NAVIGATE_BAR;
    [self.view addSubview:_redView];
    //添加大的滚动视图
    self.bigScrollerView = [[UIScrollView alloc]init];
    self.bigScrollerView.frame = CGRectMake(0, 64+40*HIGHT_SCALE, ZYAppWidth, ZYAppHeight-64-40*HIGHT_SCALE);
    self.bigScrollerView.delegate = self;
    self.bigScrollerView.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:self.bigScrollerView];
    self.bigScrollerView.pagingEnabled = YES;
    self.bigScrollerView.bounces = NO;
    self.bigScrollerView.contentSize = CGSizeMake(ZYAppWidth*2, ZYAppHeight-ZYAppHeight*HIGHT_SCALE-40*HIGHT_SCALE-64);
    for (int i = 0; i<2; i++)
    {
        UITableView * tableView = [[UITableView alloc]initWithFrame:CGRectMake(i*ZYAppWidth, 0, ZYAppWidth, ZYAppHeight-64-40*HIGHT_SCALE) style:UITableViewStylePlain];
        tableView.delegate = self;
        tableView.dataSource = self;
        [self.bigScrollerView addSubview:tableView];
    }
    

}
-(void)backBarBtnClick
{
    [self.navigationController popViewControllerAnimated:YES];
}
//点击新闻按钮
-(void)clickNewsBtn:(UIButton*)newsBtn
{
    [UIView animateWithDuration:0.3 animations:^{
        _redView.center = CGPointMake(newsBtn.center.x, newsBtn.center.y+16*HIGHT_SCALE);
    }];
    [self.bigScrollerView setContentOffset:CGPointMake(0, 0) animated:YES];
}
//点击公告按钮
-(void)clickPublicBtn:(UIButton*)publicBtn
{
    [UIView animateWithDuration:0.5 animations:^{
        _redView.center = CGPointMake(publicBtn.center.x, publicBtn.center.y+16*HIGHT_SCALE);
    }];
    [self.bigScrollerView setContentOffset:CGPointMake(ZYAppWidth, 0) animated:YES];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NewsAndPublicCell * cell = [tableView dequeueReusableCellWithIdentifier:@"newsCellID"];
    if (!cell)
    {
        cell = [[NSBundle mainBundle]loadNibNamed:@"NewsAndPublicCell" owner:nil options:nil][0];
        cell.contentView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    }
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 95;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    DSSHTaskNewsDetailVC * detailVC = [[DSSHTaskNewsDetailVC alloc]init];
    [self.navigationController pushViewController:detailVC animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
